<template>
  <div style="width: 100%; height: 100%">

    <vxe-grid ref="tableRef" v-bind="gridOptions" :data="dataList">
      <template #toolbar_buttons>
        {{timeRange}} <span style="margin-left: 5px">打卡日期:{{addDate}}</span>
      </template>
      <template #action="{ row }">
        <TableAction outside :actions="[
          {
              label:'修改',
              onClick: handleEdit.bind(null, row),
          },
           {
              label:'删除',
              color: 'error',
              loading: row.loading,
              popConfirm: {
                  title: '是否确认删除',
                  placement: 'left',
                  confirm: handleDelete.bind(null, row),
                },
             },
        ]
        " />
      </template>

    </vxe-grid>
    <FormModal @register="register" @success="handleSuccess" />

    <Modal v-model:visible="applyViewShow" title="导入信息有误" @ok="applyViewClose">
      <div>
        <p v-for="(item, index) in msgList">{{ item }} </p>
      </div>
    </Modal>
  </div>
</template>
<script lang="ts" setup>
import {
  BasicTableProps,
  VxeGridInstance,
  VxeTableDefines,
} from '@/components/VxeTable';

import { BasicTable, useTable, TableAction } from '@/components/Table';
import { useAppInject } from '@/hooks/web/useAppInject';

import { useDrawer } from '@/components/Drawer';

import {onMounted, reactive, ref} from 'vue';

import FormModal from './FormModal.vue';

import { vxeTableColumns,vxeTableFormSchema } from './role.data';
import { useMessage } from "@/hooks/web/useMessage";
import {Button, Modal} from 'ant-design-vue';
import { useGo } from "@/hooks/web/usePage";
import { pcDaKaLogList,getattcolumns } from '@/api/heng/production';
const { getIsMobile } = useAppInject();

const go = useGo();

defineOptions({ name: 'ywDeptList' });
const { createMessage } = useMessage();

// const [register, { openModal, closeModal }] = useModal();
const [register, { openDrawer,closeDrawer }] = useDrawer();

const loading=ref(false);
const msgList = ref([]);
const applyViewShow = ref(false);
const dataList=ref([]);
const tableRef = ref<VxeGridInstance>();

const timeRange=ref("");
const addDate=ref("");//

const gridOptions = reactive<BasicTableProps>({
  // keepSource: true,
  editConfig: { trigger: 'click', mode: 'cell', showStatus: true },
  border: true,
  showOverflow: true,
  size: 'mini',
  height: 'auto', // 'auto'
  columns: vxeTableColumns,
  filterConfig: {
    remote: true,
  },
  exportConfig:{},
  toolbarConfig: {
    slots: {
      buttons: 'toolbar_buttons',
    },
    export:!getIsMobile,
    print:false,
    refresh:false,
    custom:false,
    zoom:false,
  },
  formConfig: {
    // enabled: true,
    items: vxeTableFormSchema,
  },
  pagerConfig: {

    pageSize: 20,
  },
  proxyConfig: {
    props: {
      result: 'data.list',
      list: 'data.list',
      total: 'data.totalResult',
      message: 'message',
    },
    filter: true,
    ajax: {
      query: ({ page, form, filters }) => {
        return findPageList(page, form, filters);
      },
      querySuccess: ({response}) => {
        if(response.data.list.length > 0){
          timeRange.value=response.data.list[0].timeRange;
          let add=response.data.list[0].addDate;

          addDate.value=add.split(" ")[0];
        }
        // console.log(response.data.list);
      }
    },
  },
});

function findPageList(page, form, filterList?: VxeTableDefines.FilterCheckedParams<any>[]) {
  let json = {
    platform:"pc"
  };
  if (filterList && filterList.length) {
    filterList.forEach((e) => {
      const value = e.datas[0];
      let field = e.field;
      json[field ] = value;
    });
  }
  return pcDaKaLogList({
    page: page.currentPage,
    pageSize: page.pageSize,
    ...form,
    ...json,
  });
}


function handleCreate() {
  openDrawer(true, {
    isUpdate: false,
  });
}

onMounted(() => {
  //  pcDaKaLogListFn();
  // getattcolumnsFn();
})


function handleEdit(record: Recordable) {
  record.isUpdate=true;
  openDrawer(true, record);

}



function handleDelete(record: Recordable) {
  record.loading = true;

}

function handleSuccess() {
  tableRef.value.commitProxy('query');

}


function applyViewOpen() {
  applyViewShow.value = true;
}

function applyViewClose() {
  applyViewShow.value = false;
}

function getColumns() {
  let json={"columns":[
    {"extension":"null","sub_type":0,"name":"应出勤天数","alias":"should_attendance_days","expression_id":470921302,"id":470928302,"type":0,"status":0},
      {"extension":"null","expression":{"expression":"{\"expression\":\"#MakingUpLackPlug#\",\"remark\":\"expression not matched or modified\"}","expressionType":0},"sub_type":0,"name":"补卡次数","alias":"making_up_lack_times","expression_id":470921303,"id":470928303,"type":0,"status":0},
      {"extension":"null","sub_type":2,"name":"出勤班次","alias":"attendance_class","expression_id":470921304,"id":470928304,"type":0,"status":0},{"extension":"{\"hasChangeExpression\":true,\"hasChangeMemo\":false,\"hasChangeOwner\":false,\"opType\":\"UPDATE\",\"opUserId\":\"275964113925083024\"}","sub_type":0,"name":"出勤天数","alias":"attendance_days","expression_id":470921305,"id":470928305,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"if #ISRestPlug# then 1 else 0\",\"remark\":\"Not Duration Column\"}","expressionType":0},"sub_type":0,"name":"休息天数","alias":"attendance_rest_days","expression_id":470921306,"id":470928306,"type":0,"status":0},{"extension":"{\"hasChangeExpression\":false,\"hasChangeMemo\":false,\"hasChangeOwner\":false,\"opType\":\"UPDATE\",\"opUserId\":\"072522492224006756\"}","expression":{"expression":"{\"durationUnit\":1,\"unitTitle\":\"小时\",\"workTimeCount\":1}","expressionType":1},"sub_type":0,"name":"工作时长","alias":"attendance_work_time","expression_id":470921307,"id":470928307,"type":0,"status":0},{"extension":"null","sub_type":0,"name":"迟到次数","alias":"late_times","expression_id":470921308,"id":470928308,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"durationUnit\":2,\"entryDayLate\":1,\"leaveDayLate\":1,\"unitTitle\":\"分钟\",\"whetherReduction\":1}","expressionType":1},"sub_type":0,"name":"迟到时长","alias":"late_minute","expression_id":470921309,"id":470928309,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#SeriousLateCountPlug#\",\"remark\":\"Not Duration Column\"}","expressionType":0},"sub_type":0,"name":"严重迟到次数","alias":"serious_late_times","expression_id":470921310,"id":470928310,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"durationUnit\":2,\"expression\":\"#LateTimeFunctionPlug#(严重迟到,分钟)\",\"unitTitle\":\"分钟\"}","expressionType":0},"sub_type":0,"name":"严重迟到时长","alias":"serious_late_minute","expression_id":470921311,"id":470928311,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#AbsentLateCountPlug#\",\"remark\":\"Not Duration Column\"}","expressionType":0},"sub_type":0,"name":"旷工迟到次数","alias":"absenteeism_late_times","expression_id":470921312,"id":470928312,"type":0,"status":0},{"extension":"null","sub_type":0,"name":"早退次数","alias":"leave_early_times","expression_id":470921313,"id":470928313,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"durationUnit\":2,\"entryDayEarlyLeave\":1,\"leaveDayEarlyLeave\":1,\"maxReductionMinutes\":1,\"reductionMinutes\":1,\"unitTitle\":\"分钟\",\"whetherReduction\":1}","expressionType":1},"sub_type":0,"name":"早退时长","alias":"leave_early_minute","expression_id":470921314,"id":470928314,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"if #AllLackDayPlug# > 0 then 0 else #OnDutyLackCountPlug#\",\"remark\":\"Not Duration Column\"}","expressionType":0},"sub_type":0,"name":"上班缺卡次数","alias":"on_work_lack_card_times","expression_id":470921315,"id":470928315,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"if #AllLackDayPlug# > 0 then 0 else #OffDutyLackCountPlug#\",\"remark\":\"Not Duration Column\"}","expressionType":0},"sub_type":0,"name":"下班缺卡次数","alias":"off_work_lack_card_times","expression_id":470921316,"id":470928316,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#AllLackDayPlug#\",\"remark\":\"Not Duration Column\"}","expressionType":0},"sub_type":0,"name":"旷工天数","alias":"absenteeism_days","expression_id":470921317,"id":470928317,"type":0,"status":0},{"extension":"{\"expressionType\":1,\"hasChangeExpression\":true,\"hasChangeMemo\":false,\"hasChangeOwner\":false,\"opType\":\"UPDATE\",\"opUserId\":\"072522492224006756\"}","expression":{"expression":"{\"durationUnit\":3,\"unitTitle\":\"天\"}","expressionType":1},"sub_type":0,"name":"出差时长","alias":"business_trip_time","expression_id":470921318,"id":470928318,"type":0,"status":0},{"extension":"{\"expressionType\":1,\"hasChangeExpression\":true,\"hasChangeMemo\":false,\"hasChangeOwner\":false,\"opType\":\"UPDATE\",\"opUserId\":\"072522492224006756\"}","expression":{"expression":"{\"durationUnit\":1,\"unitTitle\":\"小时\"}","expressionType":1},"sub_type":0,"name":"外出时长","alias":"out_time","expression_id":470921319,"id":470928319,"type":0,"status":0},{"sub_type":0,"name":"年假","alias":"leave_","type":0,"status":0},{"sub_type":0,"name":"事假","alias":"leave_","type":0,"status":0},{"sub_type":0,"name":"病假","alias":"leave_","type":0,"status":0},{"sub_type":0,"name":"调休","alias":"leave_","type":0,"status":0},{"sub_type":0,"name":"产假","alias":"leave_","type":0,"status":0},{"sub_type":0,"name":"陪产假","alias":"leave_","type":0,"status":0},{"sub_type":0,"name":"婚假","alias":"leave_","type":0,"status":0},{"sub_type":0,"name":"丧假","alias":"leave_","type":0,"status":0},{"sub_type":0,"name":"哺乳假","alias":"leave_","type":0,"status":0},{"sub_type":0,"name":"小产假","alias":"leave_","type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#OverTimeApproveFunctionPlug#(小时)\",\"remark\":\"expression not matched or modified\"}","expressionType":0},"sub_type":0,"name":"加班-审批单统计","alias":"overtime_approve_count","expression_id":470921321,"id":470928321,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#OvertimeFunctionPlug#(小时,工作日)\",\"remark\":\"expression not matched or modified\"}","expressionType":0},"sub_type":0,"name":"工作日加班","alias":"overtime_工作日加班","expression_id":470921322,"id":470928322,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#OvertimeFunctionPlug#(小时,休息日)\",\"remark\":\"expression not matched or modified\"}","expressionType":0},"sub_type":0,"name":"休息日加班","alias":"overtime_休息日加班","expression_id":470921323,"id":470928323,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#OvertimeFunctionPlug#(小时,节假日)\",\"remark\":\"expression not matched or modified\"}","expressionType":0},"sub_type":0,"name":"节假日加班","alias":"overtime_节假日加班","expression_id":470921324,"id":470928324,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#AttendResultPlug#\",\"remark\":\"Not Duration Column\"}","expressionType":0},"sub_type":1,"name":"考勤结果","alias":"attend_result","expression_id":470921325,"id":470928325,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#PlanNameExtendPlug#\",\"remark\":\"Not Duration Column\"}","expressionType":0},"sub_type":0,"name":"班次","alias":"plan_detail","expression_id":470921326,"id":470928326,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#FirstOnDutyUserCheckTimePlug#\",\"remark\":\"Not Duration Column\"}","expressionType":0},"sub_type":0,"name":"上班1打卡时间","alias":"1_on_duty_user_check_time","expression_id":470921327,"id":470928327,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#FirstOnDutyUserCheckResultPlug#\",\"remark\":\"Not Duration Column\"}","expressionType":0},"sub_type":0,"name":"上班1打卡结果","alias":"1_on_duty_user_check_result","expression_id":470921328,"id":470928328,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#FirstOffDutyUserCheckTimePlug#\",\"remark\":\"Not Duration Column\"}","expressionType":0},"sub_type":0,"name":"下班1打卡时间","alias":"1_off_duty_user_check_time","expression_id":470921329,"id":470928329,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#FirstOffDutyUserCheckResultPlug#\",\"remark\":\"Not Duration Column\"}","expressionType":0},"sub_type":0,"name":"下班1打卡结果","alias":"1_off_duty_user_check_result","expression_id":470921330,"id":470928330,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#SecondOnDutyUserCheckTimePlug#\",\"remark\":\"Not Duration Column\"}","expressionType":0},"sub_type":0,"name":"上班2打卡时间","alias":"2_on_duty_user_check_time","expression_id":470921331,"id":470928331,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#SecondOnDutyUserCheckResultPlug#\",\"remark\":\"Not Duration Column\"}","expressionType":0},"sub_type":0,"name":"上班2打卡结果","alias":"2_on_duty_user_check_result","expression_id":470921332,"id":470928332,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#SecondOffDutyUserCheckTimePlug#\",\"remark\":\"Not Duration Column\"}","expressionType":0},"sub_type":0,"name":"下班2打卡时间","alias":"2_off_duty_user_check_time","expression_id":470921333,"id":470928333,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#SecondOffDutyUserCheckResultPlug#\",\"remark\":\"Not Duration Column\"}","expressionType":0},"sub_type":0,"name":"下班2打卡结果","alias":"2_off_duty_user_check_result","expression_id":470921334,"id":470928334,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#ThirdOnDutyUserCheckTimePlug#\",\"remark\":\"Not Duration Column\"}","expressionType":0},"sub_type":0,"name":"上班3打卡时间","alias":"3_on_duty_user_check_time","expression_id":470921335,"id":470928335,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#ThirdOnDutyUserCheckResultPlug#\",\"remark\":\"Not Duration Column\"}","expressionType":0},"sub_type":0,"name":"上班3打卡结果","alias":"3_on_duty_user_check_result","expression_id":470921336,"id":470928336,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#ThirdOffDutyUserCheckTimePlug#\",\"remark\":\"Not Duration Column\"}","expressionType":0},"sub_type":0,"name":"下班3打卡时间","alias":"3_off_duty_user_check_time","expression_id":470921337,"id":470928337,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#ThirdOffDutyUserCheckResultPlug#\",\"remark\":\"Not Duration Column\"}","expressionType":0},"sub_type":0,"name":"下班3打卡结果","alias":"3_off_duty_user_check_result","expression_id":470921338,"id":470928338,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#ApproveDetailPlug#\",\"remark\":\"Not Duration Column\"}","expressionType":0},"sub_type":0,"name":"关联的审批单","alias":"attendance_approve","expression_id":470921339,"id":470928339,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#AbsentLateCountPlug#\",\"remark\":\"Not Duration Column\"}","expressionType":0},"sub_type":0,"name":"旷工迟到天数","alias":"absenteeism_late_times","expression_id":470921340,"id":470928340,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#OvertimeDurationFunctionPlug#(小时,所有类型,全部)\",\"remark\":\"expression not matched or modified\"}","expressionType":0},"sub_type":0,"name":"加班总时长","alias":"overtime_duration","expression_id":846283067,"id":846290067,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#OvertimeDurationFunctionPlug#(小时,工作日,转加班费)\",\"remark\":\"expression not matched or modified\"}","expressionType":0},"sub_type":0,"name":"工作日（转加班费）","alias":"fee_overtime_工作日","expression_id":846283068,"id":846290068,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#OvertimeDurationFunctionPlug#(小时,休息日,转加班费)\",\"remark\":\"expression not matched or modified\"}","expressionType":0},"sub_type":0,"name":"休息日（转加班费）","alias":"fee_overtime_休息日","expression_id":846283069,"id":846290069,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#OvertimeDurationFunctionPlug#(小时,节假日,转加班费)\",\"remark\":\"expression not matched or modified\"}","expressionType":0},"sub_type":0,"name":"节假日（转加班费）","alias":"fee_overtime_节假日","expression_id":846283070,"id":846290070,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#OvertimeDurationFunctionPlug#(小时,工作日,转调休)\",\"remark\":\"expression not matched or modified\"}","expressionType":0},"sub_type":0,"name":"工作日（转调休）","alias":"rest_overtime_工作日","expression_id":846283071,"id":846290071,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#OvertimeDurationFunctionPlug#(小时,休息日,转调休)\",\"remark\":\"expression not matched or modified\"}","expressionType":0},"sub_type":0,"name":"休息日（转调休）","alias":"rest_overtime_休息日","expression_id":846283072,"id":846290072,"type":0,"status":0},{"extension":"null","expression":{"expression":"{\"expression\":\"#OvertimeDurationFunctionPlug#(小时,节假日,转调休)\",\"remark\":\"expression not matched or modified\"}","expressionType":0},"sub_type":0,"name":"节假日（转调休）","alias":"rest_overtime_节假日","expression_id":846283073,"id":846290073,"type":0,"status":0}]};
  return json;
}

function pcDaKaLogListFn2(){
  //user id  2900176627693408 沈秋权

  /**
   * 470928326 班次
   * 470928305 出勤天数
   * 470928307 工作时长
   * 470928325 考勤结果
   * 470928327 上班1打卡时间
   * 470928329 下班1打卡时间
   * 470928331 上班2打卡时间
   * 470928333 下班2打卡时间
   * 470928321 加班-审批单统计
   * 470928336 上班3打卡结果 470928335 上班3打卡时间
   * 470928338 下班3打卡结果 470928337 下班3打卡时间
   */
  let columnIdListArr=[];
  let arr=getColumns().columns;
  for (let i=0;i<arr.length;i++){
    let row=arr[i];
    if(row.id){
      columnIdListArr.push(row.id);
    }
  }
  let columnIdList="470928326,470928305,470928307,470928327,470928329,470928331,470928333";
  pcDaKaLogList({userId:"255450074837813144",columnIdList}).then((res) => {
    if(res.code==200){
     // dataList.value=res.data;
     let column_vals= res.data.column_vals;
     let columns_map=new Map();
     for(let i=0;i<column_vals.length;i++){
       let row=column_vals[i];
       for (let j=0;j<arr.length;j++) {
         let col = arr[j];
         if(col.id){
           if(row.column_vo.id==col.id){
             columns_map.set(row.name,col.id);
           }
         }

       }
     }

    }else{
      createMessage.error(res.message);
    }
  })
}


function getattcolumnsFn(){
  //user id  2900176627693408 沈秋权
  getattcolumns().then((res) => {
    if(res.code==200){
    }else{
      createMessage.error(res.message);
    }
  })
}

</script>
